/*
 * DefaultCompletionFilter.java
 *
 * Created on 2007-6-21, 23:18:58
 *
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.abigdreamer.im.client.module.main.search;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.abigdreamer.im.client.module.vo.Cache;
import com.abigdreamer.im.client.module.vo.MsgUser;
import com.abigdreamer.im.client.util.cntospell.CnToSpell;

/**
 * 
 * @author William Chen
 */
public class UserFilter implements CompletionFilter {

	private Map<String, MsgUser> friendMap;

	public UserFilter() {
		friendMap = new HashMap<String, MsgUser>();
	}

	public UserFilter(Map<String, MsgUser> v) {
		friendMap = v;
	}

	public ArrayList<String> filter(String text) {
		ArrayList<String> list = new ArrayList<String>();
		String txt = text.trim();
		int length = txt.length();

		for (String userID : friendMap.keySet()) {
			MsgUser user = Cache.getInstance().getUserByID(userID);
			if (length == 0 || user.getUserID().indexOf(txt) != -1 || CnToSpell.getFullSpell(user.getUserName()).indexOf(txt) != -1) {
				list.add(userID);
			}
		}

		return list;
	}
}
